-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QL: Remove the unnecessary DateTimeFunction.dateTimeFormat()
#68788
Conversation
…ranslations lazy Removes the `DateTimeFunction.dateTimeFormat()` method that was called, but had no effect on the translated queries. This change also adds laziness, so translations don't execute unnecessarily. Before the `ExpressionTranslators` did some unnecessary `Expression` -> `Query` translations, where the result queries were thrown away by later translations (by the `wrapFunctionQuery`). One of the examples, when this happens, is when one side of the `BinaryComparison` is a function. The `BinaryComparison` at the end turns into a `ScriptQuery`, but in the intermediate steps the `ExpressionTranslators` try to translate it to a `RangeQuery`. Follows elastic#68783
Pinging @elastic/es-ql (Team:QL) |
if (field instanceof StDistance && q instanceof GeoDistanceQuery) { | ||
return ExpressionTranslator.wrapIfNested(q, ((StDistance) field).left()); | ||
public Query wrapFunctionQuery(ScalarFunction sf, Expression field, Supplier<Query> querySupplier) { | ||
if (field instanceof StDistance && querySupplier instanceof GeoDistanceQuery) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be: querySupplier.get()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be no test for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good catch! Seems there is no test, good time to add one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides Marios' comment - and maybe apart from a missing test, if feasible - it LGTM. Good spotting on unused/-sable formats.
if (field instanceof StDistance && q instanceof GeoDistanceQuery) { | ||
return ExpressionTranslator.wrapIfNested(q, ((StDistance) field).left()); | ||
public Query wrapFunctionQuery(ScalarFunction sf, Expression field, Supplier<Query> querySupplier) { | ||
if (field instanceof StDistance && querySupplier instanceof GeoDistanceQuery) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be no test for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. However this PR needs to be broken into two - it's a bit more tedious but cleaner.
It looks to me there's a PR for removing date format and another one for adding lazy translation.
The latter in particular has subtle implications and as others have pointed out, it looks like we don't have complete testing in that area - hence the breakage.
Makes sense, will break it down into two PRs. |
DateTimeFunction.dateTimeFormat()
and turn eager query translations lazyDateTimeFunction.dateTimeFormat()
Removed the introduction of lazyness from this PR, will resubmit once this PR is merged to avoid the conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ic#68788) Removes the `DateTimeFunction.dateTimeFormat()` and the `TranslatorHandler.dateTimeFormat()` methods that were called, but had no effect on the translated queries. One of the examples, when this happens, is when one side of the `BinaryComparison` is a function. The `BinaryComparison` at the end turns into a `ScriptQuery`, but in the intermediate steps the `ExpressionTranslators` try to translate it to a `RangeQuery`. Follows elastic#68783
… (#69123) Removes the `DateTimeFunction.dateTimeFormat()` and the `TranslatorHandler.dateTimeFormat()` methods that were called, but had no effect on the translated queries. One of the examples, when this happens, is when one side of the `BinaryComparison` is a function. The `BinaryComparison` at the end turns into a `ScriptQuery`, but in the intermediate steps the `ExpressionTranslators` try to translate it to a `RangeQuery`. Follows #68783
Before the `ExpressionTranslators` did some unnecessary `Expression` -> `Query` translations, where the result queries were thrown away by later translations (by the `wrapFunctionQuery`). This change adds laziness, so translations don't execute unnecessarily. Follows elastic#68783 and elastic#68788
Removes the
DateTimeFunction.dateTimeFormat()
and theTranslatorHandler.dateTimeFormat()
methods that werecalled, but had no effect on the translated queries.
One of the examples, when this happens, is when one side of the
BinaryComparison
is a function. TheBinaryComparison
at theend turns into a
ScriptQuery
, but in the intermediate steps theExpressionTranslators
try to translate it to aRangeQuery
.Follows #68783